package com.lh.service.impl;

import com.alibaba.excel.EasyExcel;
import com.lh.entity.EduSubject;
import com.lh.dao.EduSubjectMapper;
import com.lh.entity.excel.ExcelSubjectData;
import com.lh.entity.subject.OneSubject;
import com.lh.listener.ExcelSubjectListener;
import com.lh.service.IEduSubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;

/**
 * <p>
 * 课程科目 服务实现类
 * </p>
 *
 * @author yms
 * @since 2021-06-04
 */
@Service
public class EduSubjectServiceImpl extends ServiceImpl<EduSubjectMapper, EduSubject> implements IEduSubjectService {

    @Resource
    private EduSubjectMapper eduSubjectMapper;

    /**
     * 课程列表
     *
     * @return
     */
    @Override
    public List<OneSubject> getAllSubject() {

        List<OneSubject> list= eduSubjectMapper.getAllSubject();
        return list;
    }

    /**
     * 添加课程列表
     *
     * @param file
     */
    @Override
    public void saveSubject(MultipartFile file,IEduSubjectService eduSubjectService) {

        try {
            //文件输入流
            InputStream stream = file.getInputStream();
            //调用方法进行读取
            EasyExcel.read(stream, ExcelSubjectData.class,new ExcelSubjectListener(eduSubjectService)).sheet().doRead();
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
